package com.jingdianjichi.subject.domain.service.Impl;
import com.jingdianjichi.subject.common.enums.IsDeletedCodeEnum;
import com.jingdianjichi.subject.domain.convent.SubjectCategoryConventer;
import com.jingdianjichi.subject.domain.convent.SubjectLabelConventer;
import com.jingdianjichi.subject.domain.entity.SubjectCategoryBo;
import com.jingdianjichi.subject.domain.entity.SubjectLabelBo;
import com.jingdianjichi.subject.domain.service.SubjectLabelDomainService;
import com.jingdianjichi.subject.infra.basic.entity.SubjectLabel;
import com.jingdianjichi.subject.infra.basic.service.SubjectLabelService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SubjectLabelDomainServiceImpl implements SubjectLabelDomainService {

    @Resource
    private SubjectLabelService subjectLabelService;

    @Override
    public Boolean add(SubjectLabelBo subjectLabelBo) {

        SubjectLabel subjectLabel = new SubjectLabel();
        BeanUtils.copyProperties(subjectLabelBo, subjectLabel);
        subjectLabel.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        subjectLabelService.insert(subjectLabel);
        return true;

    }

    @Override
    public Boolean update(SubjectLabelBo subjectLabelBo) {

        SubjectLabel subjectLabel = new SubjectLabel();
        BeanUtils.copyProperties(subjectLabelBo, subjectLabel);
        // subjectLabel.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        int result = subjectLabelService.update(subjectLabel);
        return result > 0;

    }

    @Override
    public Boolean delete(SubjectLabelBo subjectLabelBo) {

        SubjectLabel subjectLabel = new SubjectLabel();
        BeanUtils.copyProperties(subjectLabelBo, subjectLabel);
        subjectLabel.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        int result = subjectLabelService.update(subjectLabel);
        return result > 0;

    }


    @Override
    public List<SubjectLabelBo> queryLabelByCategoryId(SubjectLabelBo subjectLabelBo) {

        SubjectLabel subjectLabel = new SubjectLabel();
        BeanUtils.copyProperties(subjectLabelBo, subjectLabel);
        subjectLabel.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        List<SubjectLabel> subjectLabels = subjectLabelService.queryLabelByCategoryId(subjectLabel);
       // List<SubjectLabelBo> subjectLabelBoList = new ArrayList<>();
     //   BeanUtils.copyProperties(subjectLabels, subjectLabelBoList);
        List<SubjectLabelBo> subjectLabelBoList = SubjectLabelConventer.INSERT.conventBoToLabel(subjectLabels);


        return subjectLabelBoList;

    }

}
